<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('部门新增')"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">

                <div class="layui-form-item">
                    <label class="layui-form-label">部门名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="deptName" lay-verify="title" autocomplete="off" placeholder="权限名称"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">父级</label>
                    <div class="layui-input-block">
                        <ul id="selectParent" name="parentId" class="dtree" data-id="0"></ul>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">部门负责人</label>
                    <div class="layui-input-block">
                        <input type="text" id="leader" name="leader" autocomplete="off" placeholder="部门负责人" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text" id="phone" name="phone" autocomplete="off" placeholder="电话" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" id="email" name="email" autocomplete="off" placeholder="邮箱" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="status" id="status">
                            <option value="1">开启</option>
                            <option value="0">关闭</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="number" name="orderNum" autocomplete="off" placeholder="排序" class="layui-input">
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="department-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery', 'iconPicker', 'dtree','dictionary'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let iconPicker = layui.iconPicker;
        let dtree = layui.dtree;

        dtree.renderSelect({
            elem: "#selectParent",
            url: rootPath+"/SysDepartmentController/selectParent",
            method: 'get',
            selectInputName: {nodeId: "parentId"},
            skin: "layui",
            dataFormat: "list",
            response: {treeId: "id", parentId: "parentId", title: "deptName"},  //修改response中返回数据的定义
            selectInitVal: '1'
        });


        form.on('submit(department-save)', function (data) {
            data.field.icon = "layui-icon " + data.field.icon;
            $.ajax({
                url: rootPath+'/SysDepartmentController/add',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.render();
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

    })
</script>
<script>
</script>
</body>
</html>